#include <stdio.h>
#include <math.h>
/*2022.09.15 实验题目1 
设计一个贷款数额的小程序
 * 1.输入的信息：利息率、贷款的额度、贷款期限(年为单位)
 * 2.输出的信息:月还款额、总还款额(连本带息)
 * 3.算法: 每月还款额=(贷款额×月利息)/[1-1/(1+月利息)^总还款月]
 *        总还款额 = 月还款额×还款的总月数
 * 4.编写代码
 * 5.调试
*/
int main(){
    //monthlyInterest-月息，monthlyPayment-月还款额，
    float lilv,loanAmount,monthlyPayment,totalPayment,monthlyInterest;
    int year;
    printf("Enter annual interest rate,e.g.:7.25 ");
    scanf("%f",&lilv);
    printf("Enter number of years as integer,e.g.:7 ");
    scanf("%d",&year);
    printf("Enter loan amount,e.g.:120000.0 ");
    scanf("%f",&loanAmount);
    //计算月利息
    monthlyInterest = lilv/1200;
    //算法核心 计算还款情况
    monthlyPayment = loanAmount*monthlyInterest/
    (1-1/pow(1+monthlyInterest,year*12));
    totalPayment = monthlyPayment * year *12;
    //输出求得的变量,都保留两位小数，该怎么做？
    printf("The monthly payment is %.2f and the total payment is %.2f", monthlyPayment,totalPayment);

    return 0;
}